package viper.mysql;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


/**
 * @author Kevin Sin
 * 11/16/09
 * This is a test for connecting to a MySQL database from Java.  It successfully
 * printed the two entries in the test MySQL table.
 */
public class MysqlTest {

	public static void connect(){
		Connection conn = null;
		Statement statement = null;
		ResultSet rs = null;
		try {
			conn = DriverManager.getConnection("jdbc:mysql://fling.seas.upenn.edu/?" +
					"user=wksin&password=mysql4kev");
			statement = conn.createStatement();
			rs = statement.executeQuery("USE wksin");
			rs = statement.executeQuery("SELECT * FROM Testone");
			while(rs.next())
			{
				System.out.println(rs.getString("name") + "---" + rs.getString("ip_address"));
			}
		} catch(SQLException ex){
			System.out.println(ex.getMessage());
		}
	}
	
	public static void main(String[] args) {
		connect();
	}

}
